package de.baumann.browser.activitys.oc

import android.content.Context
import android.content.Intent
import android.os.AsyncTask
import android.os.Bundle
import android.util.Log
import android.view.View
import de.baumann.browser.R
import de.baumann.browser.api.net.vo.OcTransfer
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IBaseView
import de.baumann.browser.utils.StringUtil
import de.baumann.browser.utils.web3j.TokenUtil
import kotlinx.android.synthetic.main.activity_transfer_detail.*
import kotlinx.android.synthetic.main.include_tool_bar.*
import org.web3j.protocol.core.methods.response.TransactionReceipt
import kotlin.math.log

class TransferDetailActivity : BaseOdinActivity<IBaseView, BasePresenter<IBaseView>>() {

    companion object {
        fun startTransferDetailActivity(context: Context, transfer: OcTransfer,cn:String) {
            context.startActivity(Intent(context, TransferDetailActivity::class.java).apply {
                val bundle = Bundle().apply {
                    putSerializable("transfer", transfer)
                    putSerializable("cn",cn)
                }
                putExtras(bundle)
            })
        }
    }

    override fun getLayout(): Int {
        return R.layout.activity_transfer_detail
    }

    override fun getTitleText(): String {
        return "详情"
    }

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        tvHashCopy.setOnClickListener {
            StringUtil.copy(mContext, tvTDHash.text.toString())
            showShortToast("已复制到剪切板")
        }

        tvToAddressCopy.setOnClickListener {
            StringUtil.copy(mContext, tvTDToAddress.text.toString())
            showShortToast("已复制到剪切板")
        }

        tvFromAddressCopy.setOnClickListener {
            StringUtil.copy(mContext, tvTDFromAddress.text.toString())
            showShortToast("已复制到剪切板")
        }
        if (getCn()=="ODIN"){
            rlqk.visibility = View.VISIBLE
        }
    }

    override fun initData() {
        when (getTransfer().flag) {

            "out" -> {
                ivTransferFlag.setImageResource(R.drawable.zzcg)
                tvTransfer11.text = "转账成功"
            }

            "in", "air" -> {
                ivTransferFlag.setImageResource(R.drawable.skcg)
                tvTransfer11.text = "收款成功"
            }

            "fail" -> {
                ivTransferFlag.setImageResource(R.drawable.lose)
                tvTransfer11.text = "操作失败"
            }
        }

        tvTDTime.text = getTransfer().createTime
        tvTDAmount.text = "${getTransfer().amount } ${getCn()}"
        tvTDFee.text =  "${getTransfer().fee } ODIN"
        tvTDToAddress.text = getTransfer().toAddress
        tvTDFromAddress.text = getTransfer().fromAddress
        tvTDHash.text = getTransfer().hash
        tvTDBlock.text = getTransfer().block
    }

    private fun getCn():String{
        return intent.getStringExtra("cn")
    }

    override fun createPresenter(): BasePresenter<IBaseView>? {
        return null
    }

    override fun createView(): IBaseView? {
        return null
    }

    private fun getTransfer(): OcTransfer {
        return intent.getSerializableExtra("transfer") as OcTransfer
    }

    override fun showBindEth(): Boolean {
        return false
    }
}
